﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pixysoft.Framework.Logs
{
    public delegate void ThrowUnhandledExcpetion(string logId, string recordId);

    public interface ILogger
    {
        event ThrowUnhandledExcpetion OnThrowUnhandledExcpetion;

        /// <summary>
        /// 日志全局注册 用于日志之间关联查询
        /// </summary>
        /// <returns></returns>
        string Register();

        /// <summary>
        /// 注册全局异常
        /// </summary>
        void RegisterUnhandleExeption();


        /// <summary>
        /// 检查归档的日志数据 没有被打包
        /// </summary>
        /// <returns></returns>
        int CountOfFiles();

        /// <summary>
        /// 检查归档的日志数据 没有被打包
        /// </summary>
        /// <param name="millicSecAgo"></param>
        /// <returns></returns>
        int CountOfFiles(int millicSecAgo);


        /// <summary>
        /// 日志压缩包解压到当前目录
        /// </summary>
        /// <param name="zipFileFullName"></param>
        /// <returns></returns>
        string[] Unpackage(string zipFileFullName);

        /// <summary>
        /// 当前日期之前的日志打包 不包含正在处理的日志
        /// </summary>
        /// <returns></returns>
        ILogPackage Package();

        /// <summary>
        /// 当前日期之前的日志打包 不包含正在处理的日志
        /// </summary>
        /// <param name="millicSecAgo"></param>
        /// <returns></returns>
        ILogPackage Package(int millicSecAgo);


        /// <summary>
        /// 强行对当前日志归档
        /// </summary>
        void Backup();


        /// <summary>
        /// 对原有格式的日志格式化 负责现有需求，默认不跨文件
        /// </summary>
        void Format();

        /// <summary>
        /// 对原有格式的日志格式化 负责现有需求
        /// </summary>
        /// <param name="corssfiles"></param>
        void Format(bool crossfiles);


        /// <summary>
        /// 获取输入时间内的日志报告 如果格式错误 抛异常
        /// </summary>
        /// <param name="millisec"></param>
        /// <returns></returns>
        ILogReport GetRecentReport(int millisec);

        /// <summary>
        /// 获取输入时间内、制定级别的日志报告 如果格式错误 抛异常
        /// </summary>
        /// <param name="millisec"></param>
        /// <returns></returns>
        ILogReport GetRecentReport(int millisec, LogLevel level);


        /// <summary>
        ///获取制定日志ID的报告 并且包含此ID日志 默认时间范围内 其他日志内容
        /// </summary>
        ILogReport GetReport(string id);

        /// <summary>
        /// 获取制定日志ID的报告 并且包含此ID日志 在此id的millisec时间范围内 其他日志内容
        /// </summary>
        ILogReport GetReport(string id, int millisec);

        ILogRecord GetRecord(string id);

        ILogRecord GetRecord(string id, bool crossfiles);


        /// <summary>
        /// 无限制记录
        /// </summary>
        /// <param name="format"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        string All(string format, params object[] paras);

        ///// <summary>
        ///// 日志归档打包
        ///// </summary>
        //void Package();



        /// <summary>
        /// 记录debug 返回日志的id
        /// </summary>
        /// <param name="format"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        string Debug(string format, params object[] paras);

        /// <summary>
        /// 记录error 返回日志的id
        /// </summary>
        /// <param name="format"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        string Error(string format, params object[] paras);

        /// <summary>
        /// 记录info 返回日志的id
        /// </summary>
        /// <param name="format"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        string Info(string format, params object[] paras);

        /// <summary>
        /// 记录warn 返回日志的id
        /// </summary>
        /// <param name="format"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        string Warn(string format, params object[] paras);

        /// <summary>
        /// 记录fatal 返回日志的id
        /// </summary>
        /// <param name="format"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        string Fatal(string format, params object[] paras);

        /// <summary>
        /// 记录exception 返回日志的id
        /// </summary>
        /// <param name="ex"></param>
        /// <returns></returns>
        string Fatal(Exception ex);

        /// <summary>
        /// 关闭日志流
        /// </summary>
        void Close();

        /// <summary>
        /// 日志配置对象
        /// </summary>
        ILoggerSetting Setting { get;}
    }
}
